package com.sky.blog.test.mapper;

import com.sky.blog.dao.mapper.SysUserMapper;
import com.sky.blog.dao.pojo.SysUser;
import com.sky.blog.service.SysUserService;
import com.sky.blog.util.SaltUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.lang.reflect.Method;

/**
 * @author sky  2022/3/26
 * @version 1.0
 */
@SpringBootTest
public class testSysUserMapper {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private SysUserService sysUserService;

    @Test
    void testFiled() {
        Class<? extends SysUserMapper> aClass = sysUserMapper.getClass();
        Method[] methods = aClass.getDeclaredMethods();
        System.out.println(aClass.getName());
        for (int i = 0; i < methods.length; i++) {
            System.out.println(methods[i].getName());
        }
    }

    @Test
    void testInsert() {
        String password = "123456";

        String salt = SaltUtils.getSalt();
        Md5Hash hash = new Md5Hash(password, salt, 1024);
        String hex = hash.toHex();
        SysUser sysUser = new SysUser();
        sysUser.setId(0L);
        sysUser.setUsername("admin");
        sysUser.setPassword(hex);
        sysUser.setNickname("大聪明");
        sysUser.setSlogan("serialVersionUID适用于Java的序列化机制。");
        sysUser.setSalt(salt);
        sysUserMapper.insert(sysUser);

    }

    public static void main(String[] args) {
        String password = "123456";

        Md5Hash hash = new Md5Hash(password, SaltUtils.getSalt(), 1024);
        String hex = hash.toHex();
        SysUser sysUser = new SysUser();
        sysUser.setUsername("admin");
        sysUser.setPassword(hex);
        sysUser.setNickname("大聪明");
        sysUser.setSlogan("serialVersionUID适用于Java的序列化机制。");


    }
}
